﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

namespace Presentation.Reports {
  /// <summary>
  /// Report preview
  /// </summary>
  public partial class ReportViewForm : Form {

    private string reportResource;
    private string reportName;

    #region - Constructors -

    /// <summary>
    /// Initializes a new instance of the <see cref="ReportViewForm"/> class.
    /// </summary>
    public ReportViewForm( ) {
      InitializeComponent( );
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="ReportViewForm"/> class.
    /// </summary>
    /// <param name="data">The data.</param>
    /// <param name="dataMember">The data member.</param>
    /// <param name="reportName">Name of the report.</param>
    /// <param name="reportEmbeddedResource">The report embedded resource.</param>
    public ReportViewForm( DataSet data, string dataMember, string reportName, string reportEmbeddedResource )
      : this( ) {

      this.reportBindingSource.DataSource = data;
      this.reportBindingSource.DataMember = dataMember;
      this.reportResource = reportEmbeddedResource;
      this.reportName = reportName;
    }

    #endregion

    private void ReportViewForm_Load( object sender, EventArgs e ) {

      ReportDataSource report = new ReportDataSource( );
      report.Name = reportName;
      report.Value = reportBindingSource;
      reportViewer.LocalReport.DataSources.Add( report );

      reportViewer.LocalReport.ReportEmbeddedResource = reportResource;

      reportViewer.SetDisplayMode( DisplayMode.PrintLayout );
      this.reportViewer.RefreshReport( );
    }
  }
}
